package ACWing.Greed;
//148. 合并果子

import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2023/1/15 15:46
 */
public class CombinedFruit {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        Queue<Integer> queue=new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            int x=sc.nextInt();
            queue.add(x);
        }
        int sum=0;
        while (true){
            if(queue.size()==1){
                break;
            }
            int x=queue.remove();
            int y=queue.remove();
            sum=sum+x+y;
            queue.add(x+y);

        }
        System.out.println(sum);
    }
}
